package com.micro.modual.service.impl;

import com.micro.common.MicroResponseCode;
import com.micro.core.exception.BizException;
import com.micro.core.frame.service.impl.AbstractBasicsServiceImpl;
import com.micro.core.resp.RespJson;
import com.micro.modual.entity.SystemPost;
import com.micro.modual.extension.SystemPostExtension;
import com.micro.modual.mapper.SystemPostMapper;
import com.micro.modual.model.bo.systempost.PostStatusBO;
import com.micro.modual.model.bo.systempost.SystemPostBO;
import com.micro.modual.service.SystemPostService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;


/**
*  <h1>系统岗位表  实现</h1>
 * @author LevelCoder
 * @version V1.0.0
 * @email LevelCoder@126.com
 * @date 2020-08-04 00:11:10
 */
@Service("systemPostService")
public class SystemPostServiceImpl extends AbstractBasicsServiceImpl<SystemPost,Long> implements SystemPostService {

    @Autowired
    private SystemPostMapper systemPostMapper;

    /**
     * <h2>新增系统岗位表详情</h2>
     * @param systemPostBO {@link SystemPostBO} 系统岗位表 新增/修改 请求对象
     * @return {@link RespJson} 返回结果基础类
     */
    @Override
    public RespJson addSystemPost(SystemPostBO systemPostBO) {
        SystemPost systemPost = SystemPostExtension.converAddSystemPost(systemPostBO);
        systemPostMapper.insertSelective(systemPost);
        return new RespJson(MicroResponseCode.SUCCESS.getResponseCode(), MicroResponseCode.SUCCESS.getResponseMessage());
    }

    /**
     * <h2>修改系统岗位表详情</h2>
     * @param systemPostBO  {@link SystemPostBO} 系统岗位表 新增/修改 请求对象
     * @return {@link RespJson} 返回结果基础类
     */
    @Override
    public RespJson editSystemPost(SystemPostBO systemPostBO) {
        SystemPost systemPost = SystemPostExtension.converEditSystemPost(systemPostBO);
        systemPostMapper.updateByPrimaryKeySelective(systemPost);
        return new RespJson(MicroResponseCode.SUCCESS.getResponseCode(),MicroResponseCode.SUCCESS.getResponseMessage());

    }

    /**
     * <h2>根据主键编号删除系统岗位表信息</h2>
     * @param id  系统岗位表 主键编号
     * @return  {@link RespJson} 返回结果基础类
     */

    @Override
    public RespJson deleteSystemPost(Long id) {
        systemPostMapper.deleteByPrimaryKey(id);
        return new RespJson(MicroResponseCode.SUCCESS.getResponseCode(),MicroResponseCode.SUCCESS.getResponseMessage());
    }

    @Override
    public RespJson modifyPostStatus(PostStatusBO postStatusBO) {
        SystemPost systemPost = systemPostMapper.selectByPrimaryKey(postStatusBO.getPostId());
        systemPost.setPostStatus(postStatusBO.getPostStatus());
        systemPost.setUpdateTime(new Date());
        systemPostMapper.updateByPrimaryKeySelective(systemPost);
        return new RespJson(MicroResponseCode.SUCCESS.getResponseCode(),MicroResponseCode.SUCCESS.getResponseMessage());
    }

}
